<template>
  <div class="customer-container">
    <div class="create-project">
      <h1 class="page-title">创建项目</h1>

      <!-- 基本信息部分 -->
      <div class="basic-info-wrapper">
        <el-card class="basic-info-card" :body-style="{ padding: '30px' }">
          <el-row :gutter="40">
            <!-- 左侧表单 -->
            <el-col :span="12">
              <el-form label-position="left" label-width="100px">
                <el-form-item label="项目名称：">
                  <el-input />
                </el-form-item>

                <el-form-item label="活动时间：">
                  <el-input />
                </el-form-item>

                <el-form-item label="工作地点：">
                  <el-input />
                </el-form-item>
              </el-form>
            </el-col>

            <!-- 右侧日程选择 -->
            <el-col :span="12">
              <el-form label-position="left" label-width="120px">
                <el-form-item label="选择项目日程：">
                  <el-date-picker
                    v-model="projectSchedule"
                    type="datetime"
                    placeholder="请选择项目开始时间"
                    format="YYYY-MM-DD HH:mm"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    :clearable="true"
                    :editable="false"
                    :locale="locale"
                    style="width: 100%"
                  />
                </el-form-item>
              </el-form>
            </el-col>
          </el-row>
        </el-card>

        <!-- 保存按钮在卡片外左下角 -->
        <el-button type="primary" class="save-project-btn">保存项目信息</el-button>
      </div>

      <!-- 角色信息部分 -->
      <el-row :gutter="20" class="roles-section">
        <!-- 动态角色卡片 -->
        <el-col :span="8" v-for="(role, index) in roles" :key="index">
          <el-card class="role-card" :body-style="{ padding: '20px' }">
            <div class="role-header">
              <h3>角色 {{ index + 1 }}</h3>
              <el-button
                type="danger"
                size="small"
                circle
                @click="removeRole(index)"
                v-if="roles.length > 1"
              >
                <el-icon><Delete /></el-icon>
              </el-button>
            </div>
            <el-form label-position="left" label-width="90px">
              <el-form-item label="角色：">
                <el-input v-model="role.roleName" />
              </el-form-item>

              <el-form-item label="人数：">
                <el-input v-model="role.personCount" />
              </el-form-item>

              <el-form-item label="单次人数：">
                <el-input v-model="role.singlePersonCount" />
              </el-form-item>

              <el-form-item label="要求：">
                <el-input v-model="role.requirement" />
              </el-form-item>

              <el-form-item label="基础要求：">
                <el-input type="textarea" :rows="3" v-model="role.basicRequirement" />
              </el-form-item>

              <el-form-item label="工作内容：">
                <el-input type="textarea" :rows="3" v-model="role.workContent" />
              </el-form-item>

              <el-form-item label="薪资：">
                <el-input v-model="role.salary" />
              </el-form-item>
            </el-form>
          </el-card>
        </el-col>

        <!-- 添加角色按钮 -->
        <el-col :span="8" v-if="roles.length < 3">
          <div class="add-role-card">
            <el-button class="add-role-btn" size="large" @click="addRole">
              <el-icon><Plus /></el-icon>
              添加角色
            </el-button>
          </div>
        </el-col>
      </el-row>

      <!-- 底部提交按钮 -->
      <div class="submit-section">
        <el-button type="primary" size="large" class="submit-btn">提交</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { Plus, Delete } from '@element-plus/icons-vue'
import { ref } from 'vue'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'

const locale = zhCn
const projectSchedule = ref('')

const roles = ref([
  {
    roleName: '',
    personCount: '',
    singlePersonCount: '',
    requirement: '',
    basicRequirement: '',
    workContent: '',
    salary: '',
  },
])

const addRole = () => {
  roles.value.push({
    roleName: '',
    personCount: '',
    singlePersonCount: '',
    requirement: '',
    basicRequirement: '',
    workContent: '',
    salary: '',
  })
}

const removeRole = (index) => {
  roles.value.splice(index, 1)
}
</script>

<style scoped>
.customer-container {
  padding: 20px;
  background-color: #f5f5f5;
  min-height: 100vh;
}

.create-project {
  max-width: 1200px;
  margin: 0 auto;
}

.page-title {
  font-size: 24px;
  font-weight: bold;
  color: #333;
  margin-bottom: 30px;
  text-align: left;
}

/* 基本信息样式 */
.basic-info-wrapper {
  position: relative;
  margin-bottom: 60px;
}

.basic-info-card {
  background: #fdf9fa;
  margin-bottom: 20px;
}

.basic-info-card :deep(.el-card__body) {
  background: #fdf9fa;
}

.save-project-btn {
  position: absolute;
  left: 0;
  bottom: -50px;
  background: #ff69b4 !important;
  border-color: #ff69b4 !important;
}

.save-project-btn:hover {
  background: #ff1493 !important;
  border-color: #ff1493 !important;
}

/* 角色信息样式 */
.roles-section {
  margin-bottom: 30px;
}

.role-card {
  background: #fdf9fa;
  height: 100%;
}

.role-card :deep(.el-card__body) {
  background: #fdf9fa;
  height: 100%;
}

.role-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.role-header h3 {
  margin: 0;
  color: #333;
  font-size: 16px;
  font-weight: 600;
}

.add-role-card {
  height: 100%;
  min-height: 500px;
  background: #fdf9fa;
  border: 2px dashed #ccc;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.add-role-btn {
  background: transparent !important;
  border: none !important;
  color: #666 !important;
  font-size: 16px;
  padding: 40px 60px;
  transition: all 0.3s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.add-role-btn:hover {
  color: #333 !important;
  background: #e8e8e8 !important;
}

.add-role-btn .el-icon {
  font-size: 24px;
}

/* 提交按钮样式 */
.submit-section {
  text-align: center;
}

.submit-btn {
  background: #ff69b4 !important;
  border-color: #ff69b4 !important;
  padding: 12px 40px;
  font-size: 16px;
  font-weight: bold;
}

.submit-btn:hover {
  background: #ff1493 !important;
  border-color: #ff1493 !important;
}

/* Element Plus 表单样式覆盖 */
:deep(.el-form-item__label) {
  color: #333;
  font-size: 14px;
  line-height: 32px;
}

:deep(.el-input__wrapper) {
  background: #f9f9f9;
}

:deep(.el-textarea__inner) {
  background: #f9f9f9;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .basic-info-wrapper .el-col {
    margin-bottom: 20px;
  }

  .roles-section .el-col {
    margin-bottom: 20px;
  }

  .add-role-card {
    min-height: 300px;
  }
}
</style>
